<template>
	<basic-container>
		<avue-crud
			:option="option"
			:data="data"
			ref="crud"
			:table-loading="loading"
			:page="page"
			@refresh-change="refreshChange"
			@search-change="searchChange"
			@search-reset="searchReset"
			@current-change="currentChange"
			@size-change="sizeChange"
			@selection-change="selectionChange"
			@on-load="onLoad"
		>
			<template slot="menuLeft">
				<el-button type="primary" size="mini"  @click="outExcel">导出勾选</el-button>
				<el-button type="primary" size="mini"  @click="outOrderGoodsExcel">导出全部</el-button>
			</template>
		</avue-crud>
	</basic-container>
</template>
<script>
import { getList} from '@/api/account/userAccount/leadersReport.js';
import { getToken } from '@/util/store';
export default {
	data() {
		return {
			idList:[],
			isCanExOut:false,//是否能导出
			query: {},
			loading: true,
			page: {
				pageSize: 10,
				currentPage: 1,
				total: 0
			},
			obj: {},
			data: [
			],
			option: {
				size:'mini',
				border: true,
				page: false,
				tip:true,
				selection:true,
				align: 'center',
				menuAlign: 'center',
				menuType: 'button',
				editBtn: false,
				delBtn: false,
				addBtn: false,
				menu:false,
				column: [
					{
						label: '经营模式', 
						prop: 'storeTypeName',
					},
					{
						label: '是否跨区经营',
						prop: 'isCrossArea',
					},
					{
						label: '货方区域',
						prop: 'shipperName'
					},
					{
						label: '货方业务单元',
						prop: 'shipperBusinessUnitOrganizationName'
					},
					{
						label: '店铺ID',
						prop: 'tripartiteStoreId'
					},
					{
						label: '商家公司名称',
						prop: 'storeName',
						searchLabelWidth:100,
						search:true,
					},
					{
						label: '是否分销',
						prop: 'isShare'
					},
					{
						label: '销方区域',
						prop: 'regionalOrganizationStr',
						// search: true,
						// dicData: Dict.BPM_APPLY_STATUS_ENUM,
						// type: 'select',
						// props: {
						// 	label: 'label',
						// 	value: 'value'
						// }
					},
					{
						label: '销方业务单元',
						prop: 'businessUnitOrganizationStr',
					},
					{
						label: '下单用户绑定地址',
						prop: 'itemOrganizationStr',
					},
					{
						label: '团长ID',
						prop: 'groupLeaderId',
					},
					{
						label: '订单号',
						prop: 'orderId',
						search:true,
					},
					{
						label: '售价',
						prop: 'mallPrice',
					},
					{
						label: '实际成交价',
						prop: 'price',
					},
					{
						label: '营销成本',
						prop: 'marketingCost',
					},
					{
						label: '平台佣金率',
						prop: 'platformCommissionRate',
					},
					{
						label: '约定结算价',
						prop: 'agrreAmount',
					},
					{
						label: '实际结算价',
						prop: 'actualAmount',
					},
					{
						label: '约定商品差额',
						prop: 'agrreGoodsMargin',
					},
					{
						label: '实际商品差额',
						prop: 'actualGoodsMargin',
					},
					{
						label: '平台实际总收入',
						prop: 'platformActualIncome',
					},
					{
						label: '货方佣金比例',
						prop: 'shipperRate',
					},
					{
						label: '销方佣金比例',
						prop: 'sellerRate',
					},
					{
						label: '激励总比例',
						prop: 'inspireTotalRate',
					},
					{
						label: '激励总额',
						prop: 'inspireTotalAmount',
					},
					{
						label: '货方公司收入',
						prop: 'shipperCompanyIncome',
					},
					{
						label: '销方公司收入',
						prop: 'sellerCompanyIncome',
					},
					{
						label: '团长激励比例（平台）',
						prop: 'platformRewardRate',
					},
					{
						label: '团长激励额度（平台）',
						prop: 'platformReward',
					},
					{
						label: '团长激励比例（商家）',
						prop: 'storeRewardRate',
					},
					{
						label: '团长激励额度（商家）',
						prop: 'storeReward',
					},
					{
						label: '团长佣金合计',
						prop: 'reward',
					},
					{
						label: '项目激励比例（平台）',
						prop: 'itemInspireRate', 
					},
					{
						label: '项目激励额度（平台）',
						prop: 'itemInspireAmount',
					}
				]
			},
		};
	},
	methods: {
		outOrderGoodsExcel() {
			if(this.isCanExOut){
				let token = getToken();
				let storeName = this.query.storeName === undefined ? '' : this.query.storeName;
				// let addressMobile = this.query.addressMobile === undefined ? '' : this.query.addressMobile;
				let orderId = this.query.orderId === undefined ? '' : this.query.orderId;
				// let userName = this.query.userName === undefined ? '' : this.query.userName;
				// let payWay = this.query.payWay === undefined ? '' : this.query.payWay;
				// let orderStatus = this.query.orderStatus === undefined ? '' : this.query.orderStatus;
				// let reconciliationStatus = this.query.reconciliationStatus === undefined ? '' : this.query.reconciliationStatus;
				// let addTimeBegin = this.query.addTimeBegin === undefined ? '' : this.query.addTimeBegin;
				// let addTimeEnd = this.query.addTimeEnd === undefined ? '' : this.query.addTimeEnd;
				window.location.href =
						'/order/orderForm/groupLeaderOrderOutExcel?token=' +
						token +
						'&storeName=' +
						storeName +
						// '&addressMobile=' +
						// addressMobile +
						'&orderId=' +
						orderId
				// '&userName=' +
				// userName +
				// '&payWay=' +
				// payWay +
				// '&reconciliationStatus=' +
				// reconciliationStatus +
				// '&orderStatus=' +
				// orderStatus +
				// '&addTimeBegin=' +
				// addTimeBegin +
				// '&addTimeEnd=' +
				// addTimeEnd;
			}
			else {
				this.$message.error("请先保证列表正常，才能使用导出功能");
			}
		},
		outExcel() {
			console.log(this.isCanExOut)
			console.log(this.idList)
			if(this.isCanExOut&&this.idList.length>0){
				let token = getToken();
				let storeName = this.query.storeName === undefined ? '' : this.query.storeName;
				// let addressMobile = this.query.addressMobile === undefined ? '' : this.query.addressMobile;
				let orderId = this.query.orderId === undefined ? '' : this.query.orderId;
				let idList=this.idList;
				// let userName = this.query.userName === undefined ? '' : this.query.userName;
				// let payWay = this.query.payWay === undefined ? '' : this.query.payWay;
				// let orderStatus = this.query.orderStatus === undefined ? '' : this.query.orderStatus;
				// let reconciliationStatus = this.query.reconciliationStatus === undefined ? '' : this.query.reconciliationStatus;
				// let addTimeBegin = this.query.addTimeBegin === undefined ? '' : this.query.addTimeBegin;
				// let addTimeEnd = this.query.addTimeEnd === undefined ? '' : this.query.addTimeEnd;
				window.location.href =
						'/order/orderForm/groupLeaderOrderOutExcel?token=' +
						token +
						'&storeName=' +
						storeName +
						// '&addressMobile=' +
						// addressMobile +
						'&orderId=' +
						orderId +
						'&idList='+
						idList;
				// '&userName=' +
				// userName +
				// '&payWay=' +
				// payWay +
				// '&reconciliationStatus=' +
				// reconciliationStatus +
				// '&orderStatus=' +
				// orderStatus +
				// '&addTimeBegin=' +
				// addTimeBegin +
				// '&addTimeEnd=' +
				// addTimeEnd;
			}
			else {
				this.$message.error("至少选择一项！");
			}
		},
		searchReset() {
			this.query = {};
			this.onLoad(this.page);
		},
		//搜索
		searchChange(params, done) {
			this.page.currentPage = 1;
			this.query = params;
			this.onLoad(this.page, params, done);
		},
		currentChange(currentPage) {
			this.page.currentPage = currentPage;
		},
		selectionChange(list) {
			console.log(list)
			let idList = []
			if (list.length > 0) {
				for (let item of list) {
					idList.push(item.id)
				}
				console.log(idList)
				this.idList = idList
			} else {
				this.idList = [];
			}
		},
		sizeChange(pageSize) {
			this.page.pageSize = pageSize;
		},
		refreshChange() {
			this.onLoad(this.page);
		},
		onLoad(page, params = {}, done) {
			this.loading = true;
			getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
				if (done) {
					done();
				}
				this.loading = false;
				if(res.data.code==200){
					const data = res.data.data;
					this.page.total = data.count;
					// data.data.forEach(item => {
					// 	let applyArea = item.applyArea.split(',');
					// 	item.applyAreas = applyArea.join(' | ');
					// 	let storeArea = item.applyArea.split(',');
					// 	item.storeAreas = storeArea.join(' | ');
					// });
					this.data = data.data;
					this.isCanExOut = true;
				}
				else {
					this.$message.error(res.data.message);
				}

			});
		}
	}
};
</script>
<style lang="scss">
	.el-input--suffix .el-input__inner {
		padding-right: 30px!important;
	}
</style>
